unit oFormPedestrian;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, oFramePedestrian, oManager;

const
  typeNew = 1;
  typeEdit = 2;

type
  TfrmPedestrian = class(TForm)
    aFrame: TfPedestrian;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure aFramebtnOKClick(Sender: TObject);
    procedure aFramebtnEditClick(Sender: TObject);
    procedure aFramebntCancelClick(Sender: TObject);
    procedure aFrametxtCrowdTightningExit(Sender: TObject);
    procedure aFrametxtDiameterExit(Sender: TObject);
    procedure aFrametxtViewExit(Sender: TObject);
    procedure aFrametxtAvgVelocityExit(Sender: TObject);
    procedure aFrametxtMaxVelocityExit(Sender: TObject);
    procedure aFrametxtMaxAccelerationExit(Sender: TObject);
  private
    { Private declarations }
    aMaster: TManager;
    procedure checkValue(paTextBox: TLabeledEdit);
    procedure setMaster(const Value: TManager);
  public
    { Public declarations }
    property Master: TManager read aMaster write setMaster;
  end;

var
  frmPedestrian: TfrmPedestrian;

implementation

uses
  oMasterManager;

resourcestring notANumber = 'not a number';
resourcestring nameMissing = 'name undeclared';
resourcestring tooSmallDiameter = 'diameter too low';

{$R *.dfm}

{ TfrmPedestrian }

procedure TfrmPedestrian.aFramebntCancelClick(Sender: TObject);
begin
  CloseModal;
end;

procedure TfrmPedestrian.aFramebtnEditClick(Sender: TObject);
begin
  if aFrame.txtName.Text = '' then
    begin
      MessageDlg(nameMissing,mtError,[mbOK],0);
      aFrame.txtName.SetFocus;
    end else CloseModal;
end;

procedure TfrmPedestrian.aFramebtnOKClick(Sender: TObject);
begin
  if aFrame.txtName.Text = '' then
    begin
      MessageDlg(nameMissing,mtError,[mbOK],0);
      aFrame.txtName.SetFocus;
    end else CloseModal;
end;

procedure TfrmPedestrian.aFrametxtAvgVelocityExit(Sender: TObject);
begin
  checkValue(aFrame.txtAvgVelocity);
end;

procedure TfrmPedestrian.aFrametxtCrowdTightningExit(Sender: TObject);
begin
  checkValue(aFrame.txtCrowdTightning);
end;

procedure TfrmPedestrian.aFrametxtDiameterExit(Sender: TObject);
begin
  checkValue(aFrame.txtDiameter);
end;

procedure TfrmPedestrian.aFrametxtMaxAccelerationExit(Sender: TObject);
begin
  checkValue(aFrame.txtMaxAcceleration);
end;

procedure TfrmPedestrian.aFrametxtMaxVelocityExit(Sender: TObject);
begin
  checkValue(aFrame.txtMaxVelocity);
end;

procedure TfrmPedestrian.aFrametxtViewExit(Sender: TObject);
begin
  checkValue(aFrame.txtView);
end;

procedure TfrmPedestrian.checkValue(paTextBox: TLabeledEdit);
begin
  try
    StrToFloat(paTextBox.Text);
  except
    MessageDlg(paTextBox.Text + ' ' + notANumber,mtError,[mbOK],0);
    paTextBox.SetFocus;
  end;
end;

procedure TfrmPedestrian.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  aMaster := nil;
end;

procedure TfrmPedestrian.FormCreate(Sender: TObject);
begin
  aMaster := nil;
end;

procedure TfrmPedestrian.setMaster(const Value: TManager);
begin
  aMaster := Value;
  aFrame.Master := Value;
end;

end.
